﻿using MaterialDesignThemes.Wpf;
using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace Minotaur.App.Domains.ViewModel.Menu
{
    public class MenuInfoListViewModel : BindableBase
    {
        /// <summary>
        /// 创建人
        /// </summary> 
        public virtual string Creator { get; set; }

        public virtual string CreatorName { get; set; }
        /// <summary>
        /// 创建日期
        /// </summary> 
        public virtual string CreatDate { get; set; }

        /// <summary>
        /// 主键ID
        /// </summary> 
        public virtual long AutoId { get; set; }

        /// <summary>
        /// 编码
        /// </summary> 
        public virtual string? Code { get; set; }
        /// <summary>
        /// 站点地址
        /// </summary> 

        public virtual string? Address { get; set; }
        /// <summary>
        /// 图标
        /// </summary> 

        public virtual string? Icon { get; set; }
        /// <summary>
        /// 父级编码
        /// </summary> 

        public virtual string ParentCode { get; set; }
        /// <summary>
        /// 状态
        /// </summary> 

        private bool? _Status;
        /// <summary>
        /// 排序
        /// </summary> 

        public virtual long? Sequence { get; set; }

        /// <summary>
        /// 图标
        /// </summary> 
        public virtual PackIconKind IconKind { get; set; }

        /// <summary>
        /// 子集元素
        /// </summary>
        public virtual ObservableCollection<MenuInfoListViewModel> Childs { get; set; } = new ObservableCollection<MenuInfoListViewModel>();

        private string _Name;
        /// <summary>
        /// 菜单名称
        /// </summary>
        public virtual string Name
        {
            get
            {
                return _Name;
            }
            set
            {
                SetProperty(ref _Name, value);
            }
        }
        /// <summary>
        /// 选中
        /// </summary>
        private bool _isChecked = false;
        public bool IsChecked
        {
            get
            {
                return _isChecked;
            }
            set
            {
                SetProperty(ref _isChecked, value);
                //_isChecked = value; 
                ////this.RaisePropertyChanged("IsChecked");
                ////if (MenuPropertyChanged != null)
                ////    MenuPropertyChanged(this, new PropertyChangedEventArgs("IsChecked"));
            }
        }

        /// <summary>
        /// 是否显示
        /// </summary>
        public virtual Visibility IsVisible { get; set; }
        /// <summary>
        /// 左缩进类
        /// </summary>
        public virtual double MarginLeft { get; set; } = 12;

        /// <summary>
        /// 删除方法
        /// </summary>
        [Newtonsoft.Json.JsonIgnore()]
        public Action<object> DeleteAction { get; set; }

        [Newtonsoft.Json.JsonIgnore()]
        public ICommand DeleteMenuCommand => new DelegateCommand<object>(DeleteAction);

        /// <summary>
        /// 新增按钮
        /// </summary>
        [Newtonsoft.Json.JsonIgnore()]
        public Action<object> NewAction { get; set; }

        /// <summary>
        /// 新增菜单按钮
        /// </summary>
        [Newtonsoft.Json.JsonIgnore()] 
        public ICommand NewMenuCommand => new DelegateCommand<object>(NewAction);


        /// <summary>
        /// 新增按钮
        /// </summary>
        [Newtonsoft.Json.JsonIgnore()]
        public Action<object> EditAction { get; set; }

        /// <summary>
        /// 编辑菜单按钮
        /// </summary>
        [Newtonsoft.Json.JsonIgnore()] 
        public ICommand EditMenuCommand => new DelegateCommand<object>(EditAction);

        /// <summary>
        /// 行颜色
        /// </summary>
        public string RowColor { get; set; }
        public bool? Status
        {
            get => _Status;
            set
            {
                if (value.HasValue && value.Value)
                {
                    RowColor = "#108ee9";
                    DisplayStatus = "启用";                    
                }
                else
                {
                    RowColor = "#f56c6c";
                    DisplayStatus = "禁用";
                }
                _Status = value;
            }
        }

        /// <summary>
        /// 显示状态
        /// </summary>
        public string DisplayStatus { get; set; }
    }
}
